package cn.com.fuhuitong.main.cart.mode

import cn.com.fuhuitong.http.BaseAbstractManager
import cn.com.fuhuitong.http.BaseResponse
import cn.com.fuhuitong.http.ResponseSubscribeListener
import cn.com.fuhuitong.http.SubscribeListener
import cn.com.fuhuitong.main.cart.entity.CartIdsEntity
import cn.com.fuhuitong.main.cart.entity.CartListResponse
import com.blankj.utilcode.util.LogUtils
import com.google.gson.Gson
import io.reactivex.Observable
import io.reactivex.disposables.Disposable

class CartManager : BaseAbstractManager<CartApi>(CartApi::class.java) {

    /**
     * 获取购物车列表
     *
     * @param token
     */
    fun cartList(
        token: String, listener: SubscribeListener<CartListResponse>
    ): Disposable {
        val cartList: Observable<CartListResponse> = apiService.cartList(token)
        return subscribe(cartList, ResponseSubscribeListener(listener))
    }

    /**
     * 更新购物车数量
     *
     * @param token
     */
    fun cartUpdateNum(
        token: String, shopCartId: String, num: String, listener: SubscribeListener<BaseResponse>
    ): Disposable {
        val cartUpdateNum: Observable<BaseResponse> =
            apiService.cartUpdateNum(token, shopCartId, num)
        return subscribe(cartUpdateNum, ResponseSubscribeListener(listener))
    }

    /**
     * 删除购物车
     *
     * @param token
     */
    fun cartDelete(
        token: String, shopCartIds: List<String>, listener: SubscribeListener<BaseResponse>
    ): Disposable {
        val cartDelete: Observable<BaseResponse> =
            apiService.cartDelete(token, CartIdsEntity(shopCartIds))
        return subscribe(cartDelete, ResponseSubscribeListener(listener))
    }

}